/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_RTSP_MESSAGE_H
#define MK_RTSP_MESSAGE_H
#include "MkUtil/MkTypes.h"
#include "MkRtspUtil.h"

class MkApi CMkRtspMessage
{
public:
    CMkRtspMessage();
    ~CMkRtspMessage();

    const MkString& GetHeader(const MkRtspHeaderType& HeaderType)const;
    const MkMapString& GetExtensionHeaders() const { return m_MapExtension; }
    const MkString& GetExtensionHeader(const MkString& Key) const;
    const MkString& GetBody() const { return m_Body; }
    Uint32 GetCSeq() const;

    Uint32 AddExtensionHeader(const MkString& Key, const MkString& Value);
    void SetExtensionHeader(const MkMapString& ExternHeaders) { m_MapExtension = ExternHeaders; }
    Uint32 AddHeader(const MkRtspHeaderType& HeaderType, const MkString& strValue);
    Uint32 AddBody(const MkString& Body);

    Uint32 Parse(const Int8* Content, Uint32 nLen, Uint32& nUsed);
    Uint32 ToString(MkString& strRtsp);

    Uint32 ParseAuthenticate(OUT BOOL& bBasic, OUT MkString& Realm, OUT MkString& Nonce) const;
    Uint32 ParseAuthorization(OUT MkString& UserName, OUT MkString& Realm, OUT MkString& Nonce,
        OUT MkString& Uri, OUT MkString& Response) const;
protected:
    virtual Uint32 OnPacketHeaderLine(OUT MkString& strHeader) = 0;
    virtual Uint32 OnParseHeaderLine(const MkString& strHeader) = 0;
private:
    Uint32 ParseRtspHeader(const MkString& strLine, MkString& strKey, MkString& strValue);
    Uint32 CheckHeader(const MkString& Key, const MkString& Value);
    Uint32 PacketHeader(MkString& Headers);
    Uint32 GetContentLength();
private:
    MkMap<MkRtspHeaderType, MkString>			m_MapHeader;
    MkMapString					                m_MapExtension;
    MkString									m_Body;

};


#endif